const path = require('path')
const fileUtils = require('../utils/file_utils')

module.exports = async (ctx, next) => {
  const url = ctx.request.url
  if(url !== '/') {
    let filePath = url.replace('/api', '')
    filePath = '../data' + filePath + '.json'
    filePath = path.join(__dirname, filePath)
    try {
      const ret = await fileUtils.getFileJsonData(filePath)
      ctx.body = ret;
    } catch (error) {
      ctx.body = '文件资源路径不存在';
    }
    
  }
  
  await next()
}